<script setup>
function* generate1(){
    console.log("one");
    yield '1';
    console.log("two");
    yield '2'; 
    console.log("three");
    return '3';
}

function execGenerate1(){
    let gen1=generate1();
    console.log(gen1.next());
    console.log(gen1.next());
    console.log(gen1.next());
    console.log(gen1.next());
    console.log(gen1.next());
};

function* generate2(){
    console.log("start");
    let x = yield '2';
    console.log("one:" , x);
    let y = yield '3';
    console.log("two:" , y);
    console.log("total:" , (x + y));
}

function execGenerate2(){
    //next不传参
    let gen2=generate2();
    console.log(gen2.next());
    // start
    // {value: "2", done: false}
    console.log(gen2.next());
    // one:undefined
    // {value: "3", done: false}
    console.log(gen2.next());
    // two:undefined
    // total:NaN
    // {value: undefined, done: true}

    //next传参
    let gen=generate2();
    console.log(gen.next());
    // start
    // {value: "2", done: false}
    console.log(gen.next(20));
    // one:20
    // {value: "3", done: false}
    console.log(gen.next(30));
    // two:30
    // total:50
    // {value: undefined, done: true}

    for (let x of generate2()) {
        console.log(x);
    }

    let gen3=generate2();
    console.log(gen3.next());
    console.log(gen3.return("foo"));
}
</script>
<template>
    <button @click="execGenerate2">按钮</button>
</template>